package com.study.notepad.util;/*
 @Author Cedar
 @DESCRIPTION 
*/

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBUtils {


    private static ComboPooledDataSource dataSource = new ComboPooledDataSource("test");

    public static Connection getConnectionPool() {
        Connection conn = null;
        try {
            conn = dataSource.getConnection();

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }



    public static void closeConnection(Connection connection, ResultSet resultSet, Statement statement) {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            if (statement != null) {
                statement.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static DataSource getDataSource() {
        return dataSource;
    }
}
